package net.doglog;

import java.io.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class BlogServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// in web.xml we map BlogServlet to / so we should use servletPath instead of pathInfo
		Page page = PageUtil.getPage(req.getServletPath());
		if (page == null) {
			List<Post> allPosts = PostUtil.getAllPosts();
			BlogUtil.showPosts(allPosts, req, resp);
		} else {
			resp.sendRedirect(page.getLocation());
		}
	}
}
